<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>后台管理系统|GTF-Admin</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"/>
    <link rel="stylesheet" href="__PUBLIC__/admin/css/admin.css"/>
	<script src="__PUBLIC__/admin/js/jquery.js"></script>
	<script type="text/javascript" charset="utf-8" src="__PUBLIC__/uedit/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="__PUBLIC__/uedit/ueditor.all.min.js"> </script>
	<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
	<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
	<script type="text/javascript" charset="utf-8" src="__PUBLIC__/uedit/lang/zh-cn/zh-cn.js"></script>
	<style>
		.layui-form-select dl{
			z-index: 1000;
		}
	</style>
</head>
<body>
	<div class="container">
		<form class="layui-form" action="{:url('add')}" id="add">
			<div class="layui-form-item">
				<label class="layui-form-label">标题</label>
				<div class="layui-input-block">
					<input type="text" name="title" lay-verify="title" value="{$info.title}" autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">图片</label>
				<div class="layui-input-block">
					<div class="layui-upload">
						<button type="button" class="layui-btn wy-img" id="test1" data-imgurl="logo" data-inimg="demo1" data-erimg="demoText">上传图片</button>
						<input type="hidden" value="" name="logo" id="logo" />
						<div class="layui-upload-list">
							<img class="layui-upload-img" id="demo1">
							<p id="demoText"></p>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">作者</label>
				<div class="layui-input-block">
					<input type="text" name="writer" lay-verify="writer" value="{$info.writer}" autocomplete="off" placeholder="请输入作者" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">类别</label>
				<div class="layui-input-block">
					<select name="type" lay-filter="aihao">
						<option value=""></option>
						{volist name="type" id="t"}
						<option value="{$t.id}" selected="">{$t.name}</option>
						{/volist}
					</select>
				</div>
			</div>
			<div class="layui-form-item" pane="">
				<label class="layui-form-label">标签</label>
				<div class="layui-input-block">
					{volist name="tabs" id="tb"}
					<input type="checkbox" name="tabs[]" lay-skin="primary" value="{$tb.id}" title="{$tb.name}" >
					{/volist}
				</div>
			</div>
			<div class="layui-form-item" pane="">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-block">
					<input type="checkbox" name="hot[]" lay-skin="primary" value="3" title="推荐" >
					<input type="checkbox" name="hot[]" lay-skin="primary" value="2" title="置顶">
					<input type="checkbox" name="hot[]" lay-skin="primary" value="1" title="热门" >
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-block">
					<input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest" lay-text="on|off">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">内容</label>
				<div class="layui-input-block">
					<script id="editor" type="text/plain" style="width:650px;height:700px;"></script>
				</div>
			</div>
			<!--<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">编辑器</label>
				<div class="layui-input-block">
					<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>
				</div>
			</div>-->
			<input target-form="add"  type="button" value="立即提交" class="layui-btn ajax-post"/>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</form>
	</div>

	<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/xwy.js?v=3"></script>
	<script>
		var ue = UE.getEditor('editor');
		var layer,form,layedit,laydate;
		layui.use(['upload','layer','form', 'layedit', 'laydate'], function(){
			layer = layui.layer;
			form = layui.form;
			layedit = layui.layedit;
			laydate = layui.laydate;
			upload = layui.upload;
			laydate.render({
				elem: '#date'
			});
			laydate.render({
				elem: '#date1'
			});
			//自定义验证规则
			form.verify({
				title: function(value){
					if(value.length < 5){
						return '标题至少得5个字符啊';
					}
				}
				,pass: [/(.+){6,12}$/, '密码必须6到12位']
				,content: function(value){
					layedit.sync(editIndex);
				}
			});

			//监听指定开关
			form.on('switch(switchTest)', function(data){
				layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
					offset: '6px'
				});
			});
			/*
			 图片上传
			 */
			$(".wy-img").each(function (v,k) {
				var _this = $(this);
				var id = '#'+_this.attr('id');
				var inimg = '#'+_this.attr('data-inimg');
				var erimg = '#'+_this.attr('data-erimg');
				var imgurl = '#'+_this.attr('data-imgurl');
				upload.render({
					elem: id,
					url: '/upload/',
					before: function(obj){
						//预读本地文件示例，不支持ie8
						obj.preview(function(index, file, result){
							$(inimg).attr('src', result); //图片链接（base64）
						});
					},
					done: function(res){
						//如果上传失败
						if(res.code > 0){
							return layer.msg('上传失败');
						}
						//上传成功
					},
					error: function(){
						//演示失败状态，并实现重传
						var demoText = $(erimg);
						demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
						demoText.find('.demo-reload').on('click', function(){
							//uploadInst.upload();
						});
					}
				});
			});
		});
	</script>
</body>
</html>